package lxt.service.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.CostFineDao;
import lxt.entity.CostFine;
import lxt.service.CostFineService;
/**
 * 违章罚款管理service
 * @author Lit
 *
 */
public class CostFineServiceImpl implements CostFineService {
	private CostFineDao costFineDao;
	
	public boolean addCostFine(CostFine costFine) throws Exception {
		this.costFineDao.save(costFine);
		return true;
	}

	public boolean deleteCostFine(String id) throws Exception {
		String[] delId = id.split(",");
		for(int i=0;i<delId.length;i++){
			String idstr = delId[i];
			this.costFineDao.delete(CostFine.class, idstr);
		}
		return true;
	}

	public int loadAllCostFineCount(String truckId, String driverId)
			throws Exception {
		return this.costFineDao.loadAllCostFineCount(truckId, driverId);
	}

	public List<CostFine> loadCostFine(String truckId, String driverId,
			int offset, int length) throws Exception {
		List<Object> objects = this.costFineDao.loadAllCostFine(truckId, driverId, offset, length);
		List<CostFine> costFines = new ArrayList<CostFine>();//定义要传出的list
		if(objects.size()>0){
			for(int i=0;i<objects.size();i++){
				Object[] ob = (Object[])objects.get(i);
				CostFine costFine = (CostFine)ob[0];
				costFine.setDriverId((String)ob[1]);
				costFines.add(costFine);
			}
		}
		return costFines;
	}

	public CostFine loadCostFineById(String id) throws Exception {
		return (CostFine) this.costFineDao.get(CostFine.class, id);
	}

	public boolean updateCostFine(CostFine costFine) throws Exception {
		this.costFineDao.update(costFine);
		return true;
	}
	/**
	 * get set
	 * @return
	 */
	public CostFineDao getCostFineDao() {
		return costFineDao;
	}

	public void setCostFineDao(CostFineDao costFineDao) {
		this.costFineDao = costFineDao;
	}

}
